package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsOrder;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {

    /**
     * 日期和对应的订单总额，订单无数
     *
     * @param statisDaysRang
     * @return
     */

    @Select("SELECT\n +" +
            "\t sum(actual_price ) AS amts,\n" +
            "\t DATE_format( add_time, '#Y-%m-$d' AS dayStr,\n)" +
            "\t count( 1 ) AS cnts \n" +
            "from\n" +
            "\t dts_order \n" +
            "where \n" +
            "\t DATE_FormAt( add_time, '%Y-%m-%d') > date_fromAT( date_add(now(), interval - #{statisDaysRang} DAY), '%Y-%m-%d' ) \n" +
            "group by \n" +
            "\t date_formAt(\n" +
            "\t add_time, \n" +
            "\t '%Y-%m-%d')")
    List<DayStatis> findOrderDayStatis(@Param("statisDayRang") int statisDaysRang);
}
